package net.oschina.app.fragment.SideBlog;

import android.os.Bundle;
import android.view.View;

import net.oschina.app.adapter.BaseNewsBLogAdapter;
import net.oschina.app.base.BaseAdapter;
import net.oschina.app.base.BaseFragment;
import net.oschina.app.bean.GeneralBlogBean;
import net.oschina.app.bean.GeneralNewsBean;
import net.oschina.app.protocol.NewsBLogProtocol;
import net.oschina.app.util.CommonUtils;

import java.util.ArrayList;

/**
 * Created by wei03 on 2017/1/14.
 */
public class SideBlogNewBlogFragment extends BaseFragment {
    private BaseNewsBLogAdapter mBaseNewsBLogAdapter;
    private ArrayList<GeneralNewsBean> mDatas = new ArrayList<>();

    public SideBlogNewBlogFragment() {
    }

    @Override
    protected void OnSubItemClick(View view, Object data) {

    }

    @Override
    protected BaseAdapter getRvAdapter() {
        mBaseNewsBLogAdapter = new BaseNewsBLogAdapter();
        return mBaseNewsBLogAdapter;
    }

    @Override
    protected int onLoadSubData() {
        Bundle arguments = getArguments();
        String type="";
        if (arguments != null) {
            type = arguments.getString("type");
        } else {
            type = "recommend";
        }
        NewsBLogProtocol newsBLogProtocol = new NewsBLogProtocol(type);
        final GeneralBlogBean generalBlogBean = newsBLogProtocol.getData(mDatas.size());
        CommonUtils.runOnMainThread(new Runnable() {
            @Override
            public void run() {
                if (mBaseNewsBLogAdapter==null){

                    mBaseNewsBLogAdapter.setDatas(generalBlogBean.getBlogs());
                }
            }
        });
        return STATE_SUCCESS;
    }
}
